package com.xbongbong.saas.model.impl;

import com.xbongbong.paas.toolbox.util.CollectionsUtil;
import com.xbongbong.paas.toolbox.util.DateTimeUtil;
import com.xbongbong.paas.toolbox.util.StringUtil;
import com.xbongbong.pro.knowledge.base.pojo.KnowledgeBaseCountPojo;
import com.xbongbong.saas.domain.dao.KnowledgeDataDao;
import com.xbongbong.saas.domain.entity.KnowledgeDataEntity;
import com.xbongbong.saas.model.KnowledgeDataModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @description: 知识条目
 * @Author: 阮思程
 * @date: 202-06-21 17:37
 * @since v1.0
 */
@Service("KnowledgeDataModel")
public class KnowledgeDataModelImpl implements KnowledgeDataModel {

    @Resource
    private KnowledgeDataDao knowledgeDataDao;



    @Override
    public Integer insert(KnowledgeDataEntity entity) {
        long now = DateTimeUtil.getInt();
        entity.setAddTime(now);
        entity.setUpdateTime(now);
        return knowledgeDataDao.insert(entity);
    }

    @Override
    public void insertBatch(List<KnowledgeDataEntity> list) {
        knowledgeDataDao.insertBatch(list);
    }

    @Override
    public List<KnowledgeDataEntity> findEntitys(Map<String, Object> param) {
        return knowledgeDataDao.findEntitys(param);
    }

    @Override
    public Integer getEntitysCount(Map<String, Object> param) {
        return knowledgeDataDao.getEntitysCount(param);
    }

    @Override
    public Integer update(KnowledgeDataEntity entity) {
        return knowledgeDataDao.update(entity);
    }

    @Override
    public KnowledgeDataEntity getByKey(Long key, String corpid) {
        return knowledgeDataDao.getByKey(key,corpid);
    }

    @Override
    public List findEntitysWithoutSub(Map<String, Object> param) {
        return null;
    }

    @Override
    public Integer updateBatch(List<KnowledgeDataEntity> knowledgeDataEntities, String corpid) {
        return knowledgeDataDao.updateBatch(knowledgeDataEntities,corpid);
    }

    @Override
    public List<KnowledgeBaseCountPojo> getCountByKnowledgeId(String corpid ,List<Long> idList) {
        if (CollectionsUtil.isEmpty(idList)|| StringUtil.isEmpty(corpid)) {
            return null;
        }
        return knowledgeDataDao.getCountByKnowledgeId(corpid,idList);
    }

    @Override
    public Integer deleteByCorpIdKnowledgeId(String corpid,List<Long> idList) {
        if (StringUtil.isEmpty(corpid)){
            return 0;
        }
        if (CollectionsUtil.isEmpty(idList)){
            return 0;
        }
        return knowledgeDataDao.deleteByCorpIdKnowledgeId(corpid,idList);
    }

    @Override
    public List<Long> getIdListByCorpId(String corpid, List<Long> knowledgeList) {
        if (StringUtil.isEmpty(corpid)){
            return null;
        }
        if (CollectionsUtil.isEmpty(knowledgeList)){
            return null;
        }
        return knowledgeDataDao.getIdListByCorpId(corpid,knowledgeList);
    }

    @Override
    public List<String> getCorpidList() {
        return knowledgeDataDao.getCorpidList();
    }
}
